// pages/my_baoming_list/my_baoming_list.js
const app = getApp();
const $get_api = require('../../common/api').HTTP;
const wx_auth = require('../../common/wx_auth') //微信授权js
Page({

  data: {
    wx_auth:wx_auth.authApply,
    activeIndex: 0,
    scrollHeight:null,
    isLoginBtn:true,
    daka_img_bg:app.imgUrl + "daka_img_bg.png"+ app.version,
    right_row:app.imgUrl + "right_row.png"+ app.version,
    nomore:app.imgUrl + "no_more.png"+ app.version,
    activeList:[],
    select_type: 0, // page：当前页--
    tabList: {
      "top":[],
      "bottom":[],
    },
    jh_btn:app.imgUrl + "jh_icon.png"+ app.version,
    jh_num:12323,
    page_count:0, //人气商城数组
    isLoginBtn:true,
    no_more: false, 
    isLoading: true, 
    list_page: 1, 
    last_page:1,
    limit:2
  },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let _this = this;
        if(wx_auth.checkToken(1)){
            this.data.isLoginBtn = false;
            _this.shopList(1,_this.data.limit);
            _this.setData({
                page_count: _this.page_count,
                isLoginBtn:this.data.isLoginBtn,
            })
        }
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        let _this = this;
        // 构建页面参数
        let params = app.getShareUrlParams({});  //app.js分享为封装
        return {
            title: app.useConst.SET_INFO.share_obj.title,
            //   path: "/pages/order_list/order_list?" + params,
            path: "/pages/index/index?" + params,
            imageUrl: app.useConst.SET_INFO.share_obj.imageUrl
        };
    },
    gotoRenqiPage(e){
      console.log(e,"111");
      let id = e.currentTarget.dataset.upage
    },
    shopList:function(page = 1, limit = 20){
      let that = this;
        //select_type 1最新 2销量
        $get_api.orderActivityList({ 
            page:1,
            limit:limit
        }).then(r => { 
        let data = r.data.data;
        // console.log(data,"获取列表成功")
        that.data.tabList.bottom = [];
        that.data.tabList.bottom = data.list;
        that.data.last_page = Math.ceil(data.count / that.data.limit);
        console.log(data.count,"arr",that.data.limit);
        this.setData({
            "tabList.bottom":that.data.tabList.bottom
            // page_count:data.count
        })
      })
    },
     // 下拉刷新方法
     bindDownLoad() {
      let that = this;
      // console.log(that.data.list_page,"that.data.list_page",that.data.last_page);
      if (that.data.list_page >= that.data.last_page) {
      that.setData({
          no_more: true
      });
        return false;
      }
      that.getGoodsList(true, ++that.data.list_page,that.data.limit);
    },
    getGoodsList(isPage, list_page, limit = 20) {
      let _this = this;
      $get_api.orderActivityList({ 
          page: list_page || 1,
          limit:limit,
      }).then(r => { 
          let resList = r.data.data;
          let dataList = _this.data.tabList.bottom;
          let arr = resList.list;
          
          console.log(resList,"arr");
         
          if (isPage == true) {
          _this.setData({
              'tabList.bottom': dataList.concat(arr),
              isLoading: false,
          });
          console.log(_this.data.tabList.bottom,"menuArr.shops");
          } else {
          _this.setData({
              'tabList.bottom': resList.list,
              isLoading: false,
              
          });
          }
          if (_this.data.list_page >= _this.data.last_page) {
          this.setData({
              no_more: true
          });
          }
      })
    },
})